package com.demo.controller;

import com.demo.config.ConfigTest;
import com.demo.entity.Student;
import com.demo.entity.T;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.Optional;

/**
 * @author zhiqiang
 */
@RequestMapping("/test")
@RestController
@Slf4j
public class TestController {

    @Autowired
    private ConfigTest configTest;

    @GetMapping("/t1")
    public String t1() {
        return "我是你爸爸";
    }

    /**
     * 接收全端传递字符串数组
     *
     * @param t
     */
    @PostMapping("t2")
    public void receiveArray(@RequestBody T t) {
        log.info("开始处理");
        Optional.ofNullable(t).orElse(new T());
        Arrays.stream(t.getIds()).forEach(s -> System.out.println(s));
        log.info("处理完毕");
    }

    @PostMapping("t3")
    public void test(@RequestBody T t) {
        Student student = configTest.buildStudent2();
        Student student1 = configTest.buildStudent();
        System.out.println(student);
        System.out.println(student1);
    }

    @PostMapping()
    public String t2(String a,String b,String c){
        if (StringUtils.isNotBlank(a)) {
            System.out.println(a);
        }
        if (StringUtils.isNotBlank(b)) {
            System.out.println(b);
        }
        if (StringUtils.isNotBlank(c)) {
            System.out.println(c);
        }
        return "ok";
    }

    @GetMapping()
    public String t22(String a,String b,String c){
        if (StringUtils.isNotBlank(a)) {
            System.out.println(a+"222");
        }
        if (StringUtils.isNotBlank(b)) {
            System.out.println(b+"333");
        }
        if (StringUtils.isNotBlank(c)) {
            System.out.println(c+"444");
        }
        return "ok";
    }
}
